<?php

if ($_GET['token'] && $_GET['uid']){
    session_start();
    @define ( 'IN_ADMIN', TRUE );
    $_SESSION['user']['adminUid'] = $_GET['uid'];
    $_SESSION['user']['nickname'] = $_GET['nickname'];
    $_SESSION['user']['token']    = $_GET['token'];
    include_once template("admin/diary");
    exit;
}

if (!defined('IN_ADMIN')) {
    exit('Access Denied');
}

include_once (S_ROOT . './source/api_class.php');

if ($_POST['signinsubmit'])
{
	$account = $_POST['username'];
	if(isMobile($account)){
		$account = "86-".$account;
	}
	$passwd  = $_POST['password'];
 	
 	$client = new FFapiClient ( null );

    $content   = $client->getAccessToken ( $account, md5 ( $passwd ) );

    if ($content['resultData']) {
    	$msg = "success!";
        $_SESSION['user']['adminUid'] = $content['resultData']['loginInfo']['uid'];
        $_SESSION['user']['nickname'] = $content['resultData']['loginInfo']['nickname'];
        $_SESSION['user']['token']    = $content['resultData']['token'];
        
        include_once template("admin/diary");
        exit;
    }

    $msg = "false!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);
}else{
	include_once template("admin/login");
	exit;
}